package org.jeecg.modules.bigdataanalysis.wateranalysis.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beust.jcommander.Parameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.saxon.expr.Component;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.earlywarning.information.entity.EwInformation;
import org.jeecg.modules.earlywarning.information.service.IEwInformationService;
import org.jeecg.modules.earlywarning.rules.entity.EwRules;
import org.jeecg.modules.earlywarning.rules.service.IEwRulesService;
import org.jeecg.modules.equipment.gasmeter.util.BulletUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.util.*;

/**
 * @Description: 电源分析
 */
@Api(tags = "大数据分析")
@RestController
@RequestMapping("electricanalysis")
@Slf4j
public class ElectricAnalysisController extends JeecgController<EwRules, IEwRulesService> {
    @Autowired
    private IEwInformationService ewInformationService;//预警


    /**
     * @param warningTimeBegin 开始时间
     * @param warningTimeEnd   结束时间
     * @param req
     * @param ewInformation
     * @return
     */
    @AutoLog(value = "电能耗分析")
    @ApiOperation(value = "电能耗分析", notes = "电能耗分析")
    @GetMapping(value = "/queryeInformationEle")
    public Result<?> queryeBycode(@RequestParam(name = "warningTime_begin") String warningTimeBegin,
                                  @RequestParam(name = "warningTime_end") String warningTimeEnd,
                                  HttpServletRequest req, EwInformation ewInformation) {
        //存入租户id
        ewInformation.setTenantId(BulletUtil.getTenantId(req));
        //查询条件
        QueryWrapper<EwInformation> queryWrapper = QueryGenerator.initQueryWrapper(ewInformation, req.getParameterMap());
        //根据租户id及查询条件查询预警信息
        List<EwInformation> list = ewInformationService.list(queryWrapper);
        //组装挡板数据
        Map<String, Object> map = new HashMap<>();
        map.put("dNum", "0.00098m³");//电均消耗
        map.put("tzcNum", "1025kw³");//屠宰厂用量
        map.put("tlcNum", "8544kw³");//调理厂用量
        map.put("sscNum", "6542kw");//熟食厂用量
        map.put("yjList", list);//预警信息
        //熟食场分析
        List list1 = new ArrayList();
        //随机生成20条以内的随机数
        Random random = new Random();
        int i = random.nextInt(20);
        for (int a = 0; a < i; a++) {
            Map map1 = new HashMap();
            map1.put("Time", DateFormat.getDateInstance().format(new Date())); //日期
            map1.put("cost", new Random().nextInt(1000)); //費用
            map1.put("Elecrric", new Random().nextInt(1000));//电
            map1.put("yield", new Random().nextInt(1000));//产量
            map1.put("Fyjhz", new Random().nextInt(10) + "元/只");//费用均耗/只
            map1.put("Nyjhz", new Random().nextInt(10) + "m³/只");//能源均耗/只
            map1.put("Tb", new Random().nextInt(10) + "%");//同比
            list1.add(map1);
        }
        map.put("sscList", list1);//熟食厂分析

        //调理场分析
        List list2 = new ArrayList();
        //随机生成20条以内的随机数
        int c = random.nextInt(20);
        for (int a = 0; a < c; a++) {
            Map map1 = new HashMap();
            map1.put("Time", DateFormat.getDateInstance().format(new Date())); //日期
            map1.put("cost", new Random().nextInt(1000)); //費用
            map1.put("Elecrric", new Random().nextInt(1000));//电
            map1.put("yield", new Random().nextInt(1000));//产量
            map1.put("Fyjhz", new Random().nextInt(10) + "元/只");//费用均耗/只
            map1.put("Nyjhz", new Random().nextInt(10) + "m³/只");//能源均耗/只
            map1.put("Tb", new Random().nextInt(10) + "%");//同比
            list2.add(map1);
        }
        map.put("tlcList", list2);//调理厂分析
        //调理屠宰场
        List list3 = new ArrayList();
        //随机生成20条以内的随机数
        int d = random.nextInt(20);
        for (int a = 0; a < d; a++) {
            Map map1 = new HashMap();
            map1.put("Time", DateFormat.getDateInstance().format(new Date())); //日期
            map1.put("cost", new Random().nextInt(1000)); //費用
            map1.put("Elecrric", new Random().nextInt(1000));//电
            map1.put("yield", new Random().nextInt(1000));//产量
            map1.put("Fyjhz", new Random().nextInt(10) + "元/只");//费用均耗/只
            map1.put("Nyjhz", new Random().nextInt(10) + "m³/只");//能源均耗/只
            map1.put("Tb", new Random().nextInt(10) + "%");//同比
            list3.add(map1);
        }
        map.put("tzcList", list3);//屠宰厂分析
        return Result.OK(map);
    }

}
